package cn.kailangtu.dataspot.adapter;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;

import cn.kailangtu.dataspot.R;

public class TextAdapter extends RecyclerView.Adapter<TextAdapter.ViewHolder> {

    private final List<String> mData;

    public TextAdapter(List<String> data) {
        this.mData = data;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_text, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        // 实现循环滚动逻辑
        int actualPosition = position % mData.size();
        if(holder == null)
        {
            Log.d("SHOOTLEE","HOLDER is null");
        }
        else if(holder.textView == null )
        {
            Log.d("SHOOTLEE","HOLDER.TEXTVIEW IS NULL");
        }
        else {
            Log.d("SHOOTLEE","SCROLL IN1");
            holder.textView.setText(mData.get(actualPosition));
            Log.d("SHOOTLEE","SCROLL IN2");
        }
    }

    @Override
    public int getItemCount() {
        // 设置足够大的数量实现无限滚动效果
        return Integer.MAX_VALUE;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView textView;

        ViewHolder(View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.text1);
        }
    }
}